/*
 * @Description: Description
 * @Autor: Chen
 * @Date: 2020-05-15 11:04:29
 * @LastEditors: chen
 * @LastEditTime: 2021-04-29 10:46:03
 */
import { Injectable } from '@angular/core';
import { ServicesModule } from './services.module';
import { HttpClient, HttpParams } from '@angular/common/http';
import { AnyJson } from './data-types/common.type';
import { Observable, map } from 'rxjs';

@Injectable({
  providedIn: ServicesModule,
})
export class UploadfileService {
  constructor(private http: HttpClient) {}

  /**
   * @description: 上传文件
   */
  uploadFile(file: any, url: string): Observable<AnyJson> {
    const params = new FormData();
    params.append('file', file);
    return this.http.post(url, params).pipe(map((res) => res as AnyJson));
  }
  /**
   * @description: 上传图片
   */
  uploadImg(body: any): Observable<AnyJson> {
    return this.http
      .post('/upload/uploadImg', body)
      .pipe(map((res) => res as AnyJson));
  }
  /**
   * @description: 上传文件
   */
  uploadOther(body: any): Observable<AnyJson> {
    return this.http
      .post('/upload/uploadOther', body)
      .pipe(map((res) => res as AnyJson));
  }
  /**
   * @description: 上传视频
   */
  uploadVideo(body: any): Observable<AnyJson> {
    return this.http
      .post('/upload/uploadVideo', body)
      .pipe(map((res) => res as AnyJson));
  }
}
